<%@page import="com.DAO.*"%>
<%@page import="java.util.*"%>

<%@taglib  prefix="html" uri="/tags/struts-html" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="com.beans.*,java.util.*,java.text.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel = "stylesheet" href = "style/Global.css">
</head>
<body>
	 <%! int notice_id; %>
	<% 
    NoticeForm noticeForm=(NoticeForm)session.getAttribute("noticeform");

    notice_id=noticeForm.getNoticeId();
    String title=noticeForm.getTitle();
	String description=noticeForm.getDescription();
	String creatorid=noticeForm.getCreatorId();
	String creatorname=noticeForm.getCreatorName();
		
	DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	String date=dateFormat.format(noticeForm.getCreatedDate());
	
	//String currentDate = dateFormat.format(d);
    CategoryDAO catdao=new CategoryDAO();
	
	String allowComments=catdao.getCategoryInfo(noticeForm.getCategoryId()).getAllowComment();
	request.setAttribute("notice_id",notice_id);
	String categoryName = catdao.getCategoryInfo(noticeForm.getCategoryId()).getName();
%>
	<div class = "categorytitle">
	       	       
	         <%=categoryName%>
	        
	                   
	</div>
		<div id = "noticeheading">
			
			<%			if((session.getAttribute("userid").toString().equals(creatorid)) ||
						(session.getAttribute("user_type").toString().equals("admin")))
						{ %>
			<a class = "btndelete" href = "DeleteNoticeAction.do?notice_id=<%=notice_id%>" >
				<img alt = "delete" src = "image/31.png" height="25" width="20" align="top">
			</a>
			<%} %>
			
			<div id = "createddate">
				on&nbsp;<%=date %>&nbsp;
			</div>
			<div id = "creatorname">
				by&nbsp; <%=creatorname %>&nbsp;
			</div>			
			
			<div id = "noticetitle">
				<%=title%>
			</div>
				
		</div>
	<div id = "description"><%=description %></div>
	<%
	  
	if(allowComments.equals("T")) {    %>
	<form id = "commentform" action="CommentForm.do?notice_id=<%=notice_id%>" method="post">
	
	
	<div id = "addcomment">Add Comment</div>
	
	
	<textarea id = "txtcomment" name="description" ></textarea><br>
	
	<html:errors/>
	
	<div>
		<input id = "btnsubmit" type="image" name = "submit" onclick="form.submit();" value = "Submit" src="image/27.jpg">
	</div>
	
	
	</form>
	
	<div id = "commentonnotice">
	<%!ArrayList<CommentForm> alist=null; %>
<% 
   alist=(ArrayList<CommentForm>)session.getAttribute("listComments");
%>	<span id = "comhead">Comments: </span>
	<ul>
		<%
			for (CommentForm commentForm :alist) {
				int cid=commentForm.getId();
				String desc = commentForm.getDescription();
				String notice_creatorid = commentForm.getCreatedById();
				String comment_creator = (new UserDAO()).getUsernameById(notice_creatorid );
				String expdate = commentForm.getCreatedDate().toString();
				String d[]=expdate.split("-");
				expdate=d[2]+"/"+d[1]+"/"+d[0];
		%>
			
		<li>
			<div class = "commentheading">
			
			<div class = "commentedby"><img alt="user" src = "image/user-icon.png" height = "25" width = "25" align="top">&nbsp;&nbsp;&nbsp;<%=comment_creator%></div>
			
				<%			if((session.getAttribute("userid").toString().equals(notice_creatorid)) ||
						(session.getAttribute("user_type").toString().equals("admin")))
						{ %>
	<a class = "btndelete" href="DeleteComment.do?cid=<%=cid%>">					
	     <img alt = "delete" src = "image/31.png" height="25" width="20" align="top">
	</a>	
<%	}%>
	<div class = "createdon"><%=expdate %></div>
			</div>
			
			<div class = "commenttext"><%=desc%> </div>
		</li>
		<%}%>
	</ul>
	</div>
	<%} %>
</body>
</html>